package com.jwsoft.manager.gateway.controller.demo;

import cn.hutool.core.convert.Convert;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.business.integration.demo.DemoIntegration;
import com.jwsoft.manager.common.vo.demo.DemoTestDetailVO;
import com.jwsoft.manager.common.vo.demo.DemoTestVO;
import com.jwsoft.manager.gateway.req.DemoTestDetailReq;
import com.jwsoft.manager.gateway.req.DemoTestReq;
import com.xiaoyy.core.common.validators.Validators;
import com.xiaoyy.core.common.vo.AppResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/demo/test")
@Api(tags = "框架例子")
public class DemoController {
    @Autowired
    DemoIntegration demoIntegration;

    @PostMapping(value = "/query/getList", produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "分页查询例子", notes = "分页查询例子")
    public AppResponse<PageInfo<DemoTestVO>> getList(@RequestBody DemoTestReq req) {
        DemoTestVO vo = Convert.convert(DemoTestVO.class, req);
        return AppResponse.successData(demoIntegration.getList(vo));
    }
    @PostMapping(value = "/query/getDetail", produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "单个查询例子", notes = "单个查询例子")
    public AppResponse<DemoTestVO> getDetail(@RequestBody @Validated DemoTestDetailReq req) {
        DemoTestDetailVO vo = Convert.convert(DemoTestDetailVO.class, req);
        return AppResponse.successData(demoIntegration.getDetail(vo));
    }
    @PostMapping(value = "/save", produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "保存例子", notes = "保存例子")
    public AppResponse<DemoTestVO> save(@RequestBody @Validated(value = {Validators.Add.class}) DemoTestReq req) {
        DemoTestVO vo = Convert.convert(DemoTestVO.class, req);
        return AppResponse.successData(demoIntegration.save(vo));
    }
    @PostMapping(value = "/del", produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "删除例子", notes = "删除例子")
    public AppResponse del(@RequestBody @Validated DemoTestDetailReq req) {
        DemoTestDetailVO vo = Convert.convert(DemoTestDetailVO.class, req);
        demoIntegration.del(vo);
        return AppResponse.success();
    }
}
